Skip to content

feat: re-write uuid functions (calls + DEFAULT) in omni insert - #1556

Merged
jkaczman merged 2 commits into
mainfrom
jk-omni-writes-uuid-func
Sep 16, 2026
Merged

jkaczman merged 2 commits into
mainfrom
jk-omni-writes-uuid-func

Conversation

@jkaczman

@jkaczman jkaczman commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Adds support to rewrite UUID functions (uuidv4, uuidv7, gen_random_uuid) for omni inserts on top of the support for date-time functions (from #1541). Some refactoring to push those two classes of functions into separate files and generalize handling a bit more.

It does not support specifying an interval argument within uuidv7() yet.

@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.56057% with 65 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...r/rewrite/statement/non_deterministic_funcs/mod.rs 85.03% 38 Missing ⚠️
.../rewrite/statement/non_deterministic_funcs/time.rs 86.86% 18 Missing ⚠️
.../rewrite/statement/non_deterministic_funcs/uuid.rs 65.38% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

@jkaczman
jkaczman marked this pull request as ready for review September 16, 2026 19:08

@levkk levkk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@jkaczman
jkaczman changed the base branch from main to jk-bump-postgres-in-ci September 16, 2026 20:09
@jkaczman
jkaczman added this pull request to stack #1566 September 16, 2026 20:09
@jkaczman
jkaczman force-pushed the jk-omni-writes-uuid-func branch 2 times, most recently from e5c7b00 to 35e6e1c Compare September 16, 2026 21:05
Base automatically changed from jk-bump-postgres-in-ci to main September 16, 2026 21:49
@jkaczman
jkaczman force-pushed the jk-omni-writes-uuid-func branch from 35e6e1c to 1d6511c Compare September 16, 2026 21:49
@jkaczman
jkaczman merged commit 7235dd7 into main Sep 16, 2026
28 of 29 checks passed
@jkaczman
jkaczman deleted the jk-omni-writes-uuid-func branch September 16, 2026 22:15
Comment on lines +67 to +69
/// Why do we need to cast? This is because, for example, if we try to use CURRENT_TIME (timetz) with a
/// text column in a binary format Bind param, Postgres will error without an explicit cast (expected UTF-8).
/// The alternative is manually calculating the binary format, which is a lot more of a headache! :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is correct. We don't send OIDs when rewriting the parse message, so it'll always be an inferred type depending on the position. If it's in a ResTarget on the values list for an insert or update, it'll be inferred to the type of the column, while in all other cases it'll almost certainly be inferred to text.

None of this should be necessary if we start sending the appropriate types in our rewritten Parse messages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. This wasn't my first attempt; I came to this workaround after I was unable to get it to work without any special treatment. Postgres was throwing errors with the extended protocol in relation to how the binary format was assembled in the Bind message. There's certainly a chance I was doing something wrong, missing something, or perhaps there's a bug somewhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, bind parameters of the incorrect type are far more likely to work incidentally over the text protocol, since the same string can be a valid value across multiple types, and the fallback type for a parameter when one can't be inferred is text (casting a text parameter to another type is the same as sending a value of that type using the text protocol)

The type of a bind parameter is only going to be inferrable some of the time. (inserts and updates for sure, selects will depend on context). When it can't be inferred, it'll fall back to text. The correct binary repr of a time/timestamp is unlikely to be valid UTF-8 so it'll cause a decoding error when that happens. Sending the OID means that PG will always know we intended to send the timestamptz, so sending the binary repr (which we should prefer in this case because dealing with text representations of dates/times is much more expensive than something like an integer) will always be interpreted the correct way

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thank you for explaining. I can work on fixing this as part of my WIP refactor for supporting SELECT rewrites for functions that rely on transaction time (#1624)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but we should touch base to make sure we don't step on each other's toes. I'm doing a pretty significant refactor of this part of the code base right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants